package br.com.univas.si6.sd1.jogo.server;

import java.io.ObjectInputStream;
import java.net.Socket;

import br.com.univas.si6.sd1.jogo.client.ClientPlayer;

public class ReceivePlayer implements Runnable{
	
	private ResultSender resultSender = ResultSender.getInstance();
	private Socket socket;
	
	public ReceivePlayer(Socket socket) {
		this.socket = socket;
	}

	@Override
	public void run() {

		try {
			ObjectInputStream objectOutputStream = new ObjectInputStream(socket.getInputStream());
			ClientPlayer clientPlayer = (ClientPlayer) objectOutputStream.readObject();
			
			ServerPlayer serverPlayer = new ServerPlayer(clientPlayer.getNome(), socket, clientPlayer.getJogada());
			resultSender.addPlayer(serverPlayer);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
